import 'package:flare_flutter/flare_actor.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

int logicMultiCount = 0;

class LoadingWidget extends StatelessWidget {
  final double? width;

  final double? height;

  const LoadingWidget({super.key, this.width = 40, this.height = 20});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width,
      height: height,
      child: const FlareActor(
        'assets/flare/loading.flr',
        alignment: Alignment.center,
        fit: BoxFit.contain,
        animation: "loading",
      ),
    );
  }
}

class LoadingCenterWidget extends StatelessWidget {
  final double? width;
  final double? height;
  static int showCount = 0;
  const LoadingCenterWidget({super.key, this.width = 40, this.height = 20});

  static show() async {
    showCount++;
    await Get.dialog(const LoadingCenterWidget());
    showCount--;
  }

  static cancel() {
    if (showCount > 0) {
      Get.back();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: LoadingWidget(
        width: width,
        height: height,
      ),
    );
  }
}
